/**
  * @file euclid.cpp
  */

  /* Copyright 2010 Antonio Ruano Cuesta
 *
 * This program is free software: you can redistribute it and/or modify it under 
 * the terms of the GNU General Public License as published by the Free Software 
 * Foundation, either version 3 of the License, or (at your option) any later 
 * version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT 
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with 
 * this program. If not, see <http://www.gnu.org/licenses/>
*/
  
#include <iostream>
#include "cto_prototipo.h"
#include "func_aux.h"
using namespace std;


/**
  * @brief Funcion principal que gestiona el calculo de la clasificacion de un conjunto 
  * de prototipos con el metodo de minima distancia euclidea.
  */
int main (int argc, char *argv[])
{
	if (argc != 4 && argc != 5){
		cerr<<"Numero de argumentos incorrecto."<<endl;
		cerr<<"Formato de la llamada: euclid fich_a_clasif fich_aprend fich_rdo [fich_test]"
			<<endl;
		exit(1);
	}

	char *fich_clasif, *fich_aprend, *fich_rdo;
		
	fich_clasif = argv[1];
	fich_aprend = argv[2];
	fich_rdo = argv[3];

	cto_prot ctoclasif, ctoaprend;

	ctoclasif.InsertarDesdeFichero (fich_clasif);

	ctoaprend.InsertarDesdeFichero (fich_aprend);

	ctoclasif.ClasifMinDisteuclidea (ctoaprend);

	ctoclasif.GuardarEnFichero (fich_rdo);

	if (argc == 5){

		char *fichtest = argv[4];
		
		cto_prot ctotest,ctoaux;
		
		ctotest.InsertarDesdeFichero(fichtest);
		ctoaux.InsertarDesdeFichero(fichtest);

		ctoaux.ClasifMinDisteuclidea(ctoaprend);

		int **confusion = ctotest.CalculoMatrizConfusion(ctoaux);
		
		//Impresión de la matriz de confusión
		ImpresionMatrizConfusion(confusion,ctoaprend.get_numclas());
		
		for (unsigned int i = 0 ; i < ctoaprend.get_numclas() ; i++)
			delete [] confusion[i];

		delete[]confusion;

		
	}

}

